﻿<?php
require_once("./include/db_info.inc.php");
require_once("./bm-header.php");
require_once("./include/funcs.php");
//取消报名
if (isset($_GET['cid']))
{
	$bm_c_id=intval($_GET['cid']);
	$sql="SELECT * FROM `bm_contest` WHERE `bm_c_id`='$bm_c_id' ";
	$result=mysql_query($sql);
	$rows_cnt=mysql_num_rows($result);
	$contest_ok=true;
	if ($rows_cnt==0)
	{
		header("Location: $BM_HOME/contest.php?cid=".$bm_c_id);
	}
	else
	{
		$row=mysql_fetch_object($result);
		$now=time();
		$Ckind=$row->bm_c_kind;
		$SRtime=strtotime($row->bm_c_startreg);
		$ERtime=strtotime($row->bm_c_endreg);
		$bm_c_defunct=$row->bm_c_defunct;
		$view_description=$row->bm_c_description;
		$view_title= $row->bm_c_title;
		$view_start_time=$row->bm_c_start;
		$view_end_time=$row->bm_c_end;
		$view_SRtime=$row->bm_c_startreg;
		$view_ERtime=$row->bm_c_endreg;
		if ($row->bm_c_defunct=='Y' || !isset($_SESSION['user_id'])
			|| $now < $SRtime || $now > $ERtime) $contest_ok=false;
		if (isset($_SESSION['administrator'])) $contest_ok=true;
	}
	if (!$contest_ok)
	{
		header("Location: $BM_HOME/contest.php?cid=".$bm_c_id);
	}
	$bm_t_ojid=$_SESSION['user_id'];
	$sql="SELECT * FROM `bm_team` WHERE `bm_c_id`=$bm_c_id AND `bm_t_ojid`='$bm_t_ojid'";
	$result=mysql_query($sql);
	if(mysql_num_rows($result) == 0)
	{
		header("Location: $BM_HOME/contest.php?cid=".$bm_c_id);
	}
	$row=mysql_fetch_assoc($result);
	$bm_t_id=$row['bm_t_id'];
	mysql_free_result($result);
	$sql="DELETE FROM `bm_stu` WHERE `bm_t_id`=$bm_t_id";
	mysql_query($sql) or die(mysql_error());
	$sql="DELETE FROM `bm_team` WHERE `bm_t_id`=$bm_t_id";
	mysql_query($sql) or die(mysql_error());
}
else
{
	header("Location: $BM_HOME");
}
?>
<script type="text/javascript">     
function countDown(secs,surl){     
 //alert(surl);     
 var jumpTo = document.getElementById('jumpTo');
 jumpTo.innerHTML=secs;  
 if(--secs>0){     
     setTimeout("countDown("+secs+",'"+surl+"')",1000);     
     }     
 else{       
     location.href=surl;     
     }     
 }     
</script>
<h3>取消报名成功，<span id="jumpTo">2</span>秒后自动跳转</h3>
<?php
	echo "<script type='text/javascript'>countDown(2,'$BM_HOME/contest.php?cid=".$bm_c_id."');</script>";
	require_once("./bm-footer.php");
?>  